<?php namespace App\Http\Controllers;

use DB;
use Auth;
use App\Collect;
use App\Http\Request\Userinfo;

class UserController extends BaseController
{

    /**
     * @description ajax添加到我的收藏
     * @param int $uid
     * @param int $tid
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function toCollect($uid, $tid)
    {
        if( Collect::whereRaw('uid = :uid and title_id = :tid', [$uid, $tid])->count() == 0 )
        {
            Collect::create([
                'uid' => $uid,
                'title_id' => $tid,
                'time' => time()
            ]);

            return response()->json(['error' => 0]);
        }
        else
            return response()->json(['error' => 1]);
    }

    /**
     * @description 我的收藏列表
     * @return \Illuminate\View\View
     */
    public function Collect()
    {
        $collect_title_id = $this->mycollect(null, false);

        $data = DB::table('house_info')->whereIn('title_id', $collect_title_id)->paginate(10);

        return View('user.collect', compact('data'));
    }

    /**@description 用户信息
     * @return \Illuminate\View\View
     */
    public function userinfo()
    {
        return View('user.userinfo');
    }

    public function editUserInfo(Userinfo $request)
    {
        $info = $request->except('_token');

    }

    public function uploadhead()
    {

    }

}
